#include "led.h"

void led_fun(char *uled)
{
    uint8_t temp = 0x00;
    static uint8_t temp_old = 0xff;

    for (uint8_t i = 0; i < 8;i++)
        temp |= uled[i] << i;

        if(temp != temp_old)
        {
            GPIOC->ODR &= 0x00ff;
            GPIOC->ODR |= ~(temp << 8);

            GPIOD->BSRR |= 0x01 << 2;
            GPIOD->BRR |= 0x01 << 2;

            temp_old = temp;
        }
}

uint8_t uled[8] = {0,0,0,0,0,0,0,0};
uint32_t Old_led_timer = 0;
void led_proc(void)
{
    uled[0] = !show_mode;
    uled[1] = show_mode;
    if(adc_value_ref<adc_value)
    {
        uint32_t Current_led_timer = HAL_GetTick();
        if(Current_led_timer >= Old_led_timer + 100)
        {
            uled[2] ^= 1;
            Old_led_timer = Current_led_timer;
        }
    }
    else
    {
        uled[2] = 0;
    }
    led_fun(uled);
}
